from dataclasses import dataclass

from common.requests_until import logger


@dataclass
class CaseCheckInfo:

    # 必填
    feature: str
    story: str
    title: str
    request: dict
    validate: dict
    # 选填
    extract: dict = None
    parametrize: dict= None

#校验测试用例
def verify_yaml(caseinfo: dict,yaml_name):

    try:
        new_caseinfo = CaseCheckInfo(**caseinfo)
        return new_caseinfo
    except Exception:
        logger.error(yaml_name+" YAML测试用例不符合框架的规范！" + "\n")
        raise Exception("YAML测试用例不符合框架的规范！")



# if __name__ == '__main__':
#     a = {
#         'feature': '本地项目',
#         'story': '新增用户接口',
#         'title': '验证新增用户接口新增成功',
#         'request': {
#             'method': 'post',
#             'url': "http://127.0.0.1:7001/api/qingfeng/user",
#             'header': {
#                 "Content-Type": "application/json"
#             },
#             'json': {
#                 'username': 'ggl001',
#                 'phone': '12345678901'
#             }
#         },
#         'validate': None
#     }
#     new_caseinfo = verify_yaml(a)
#     print(new_caseinfo.feature)
#     print(new_caseinfo.title)
#     print(new_caseinfo.request)
#     print(new_caseinfo)